package webreg.model.container;

import java.util.Iterator;
import java.util.TreeSet;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import webreg.model.Athlet;


/** This class wraps multiple 
 * athlets in one container class for persistence.
 * 
 * @author STKNOLL
 */
@XmlRootElement(name = "athletContainer")
public class AthletContainer {

	/** Vector containing the athlets */
	private TreeSet<Athlet> mAthlets;

	/** Constructor of a athlet container */
	public AthletContainer() {
		mAthlets = new TreeSet<Athlet>( new AthletComparator() );
	}
	
	/** Constructor of an athlet container
	 * 
	 * @param athlets The athlets to store.
	 */
	public AthletContainer(TreeSet<Athlet> athlets) {
		mAthlets = athlets;
	}
	
	/** Copy constructor for athlet container
	 * 
	 * Private copy constructor for a athlet container
	 * 
	 * @param toCopy The athlet container to copy
	 */
	public AthletContainer (AthletContainer toCopy) {
		this(toCopy.mAthlets);
	}
	
	/** Implementation of the equals method.
	 * 
	 * @param toCompare The athlet container to compare with
	 * @return True, if athlet matches
	 */
	public boolean equals(AthletContainer toCompare) {
		Iterator<Athlet> iter = this.mAthlets.iterator();
		Iterator<Athlet> iter2 = toCompare.mAthlets.iterator();
		for (; iter.hasNext() && iter2.hasNext(); ) {
			Athlet athlet1 = (Athlet)iter.next();
			Athlet athlet2 = (Athlet)iter2.next();
			if (athlet1.equals(athlet2) == false) return false;
		}
		return true;
	}

		
	/** Sets the athlets that are stored in the container
	 * 
	 * @param athlets The athlets to hold in the container
	 */
	public void setAthlets(TreeSet<Athlet> athlets) {
		mAthlets = athlets;
	}

	/** Gets the stored athlets of the container
	 * 
	 * @return The athlets stored in the container.
	 */
	@XmlElement(name = "Athlet")	
	public TreeSet<Athlet> getAthlets() {
		return mAthlets;
	}

}
